/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved. 
 */
package com.icinfo.cloud.provider.punish.config.service.impl;

import com.icinfo.cloud.provider.punish.config.mapper.ConfigCaseTagMapper;
import com.icinfo.cloud.provider.punish.config.model.ConfigCaseTag;
import com.icinfo.cloud.provider.punish.config.service.IConfigCaseTagService;
import com.icinfo.cloud.provider.punish.config.vo.CaseTagVo;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述: 案件标签表 case_tag_record 对应的Service接口实现类.<br>
 *
 * @author framework generator
 * @date 2022年02月23日
 */
@Service
public class ConfigCaseTagServiceImpl extends MyBatisServiceSupport implements IConfigCaseTagService {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(ConfigCaseTagServiceImpl.class);

    @Autowired
    private ConfigCaseTagMapper caseTagRecordMapper;

    /***
     * 获取标签多级名称列表
     * @author lxj
     * @date  2022/2/23
     * @return  List
     **/
    @Override
    public List<CaseTagVo> getCaseTagList() {

        List<ConfigCaseTag> tagRecordList = caseTagRecordMapper.selectAll();
        if(tagRecordList==null||tagRecordList.size()==0){
            return null;
        }
        List<CaseTagVo>  list = new ArrayList<>();
        for (int i=0 ;i<tagRecordList.size();i++){
            ConfigCaseTag caseTagRecord = tagRecordList.get(i);
            if(caseTagRecord.getType()==1){
                CaseTagVo vo = new CaseTagVo();
                vo.setId(caseTagRecord.getId());
                vo.setTagName(caseTagRecord.getTagName());
                vo.setTagCode(caseTagRecord.getTagCode());
                //查询所有子类
                List<ConfigCaseTag> records = new ArrayList<>();
                for(int j=0 ;j<tagRecordList.size();j++){
                    ConfigCaseTag caseTag = tagRecordList.get(j);
                    if(caseTag.getType()==2&&caseTagRecord.getId().intValue()==caseTag.getParentId().intValue()){
                        records.add(caseTag);
                    }
                }
                vo.setChildren(records);
                list.add(vo);
            }
        }
        return list;
    }
}